using System;
using System.Windows.Forms;

namespace PortMap
{
	class WindowManager
	{
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#region Main Form
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// If the ServiceListForm is currently open, it is returned.
		/// Otherwise, returns null;
		/// </summary>
		public static Form1 GetMainForm()
		{
			foreach (Form form in Application.OpenForms)
			{
				if (form is Form1)
				{
					return (Form1)form;
				}
			}
			return null;
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#endregion
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#region Add Mapping Form
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// If the AddMappingForm is already open, it is brought to the front.
		/// Otherwise, a new AddMappingForm is opened and shown.
		/// </summary>
		/// <returns>
		///		The AddMappingForm that was displayed.
		/// </returns>
		public static AddMappingForm ShowAddMappingForm()
		{
			foreach (Form form in Application.OpenForms)
			{
				if (form is AddMappingForm)
				{
					form.BringToFront();
					return (AddMappingForm)form;
				}
			}

			AddMappingForm newForm = new AddMappingForm();
			newForm.Show();

			return newForm;
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#endregion
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#region Add Mapping Form
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// If the AllMappingsForm is already open, it is brought to the front.
		/// Otherwise, a new AllMappingsForm is opened and shown.
		/// </summary>
		/// <returns>
		///		The AllMappingsForm that was displayed.
		/// </returns>
		public static AllMappingsForm ShowAllMappingsForm()
		{
			foreach (Form form in Application.OpenForms)
			{
				if (form is AllMappingsForm)
				{
					form.BringToFront();
					return (AllMappingsForm)form;
				}
			}

			AllMappingsForm newForm = new AllMappingsForm();
			newForm.Show();

			return newForm;
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
		#endregion
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	}
}
